package encryption;

import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;

public class RSADecryptor {
	
	public static final String algorithm = "RSA";
	
	public static final String PRIVATE_KEY_FILE = "C:/RSAKeys/private.key";
	
	public static String decrypt(byte[] text, PrivateKey key) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException{
		
		byte[] decryptedText = null;
		
		Cipher cipher = Cipher.getInstance(algorithm);
		
		cipher.init(Cipher.DECRYPT_MODE, key);
		
		decryptedText = cipher.doFinal(text);
		
		return new String(decryptedText);
	}

}
